// 厦门大学计算机专业 | 前华为工程师
// 专注《零基础学编程系列》  http://lblbc.cn/blog
// 包含：Java | 安卓 | 前端 | Flutter | iOS | 小程序 | 鸿蒙
// 公众号：蓝不蓝编程

import AlertToast
import SwiftUI
import SDWebImageSwiftUI


struct GoodsView: View {
    @StateObject private var viewModel = GoodsViewModel()
    @State var goods: Goods
    @State private var showToast = false
    var body: some View {
        VStack{
            WebImage(url: URL(string: goods.squarePic ?? ""))
                .placeholder{Color.gray}
                .resizable()
                .scaledToFit()
                .frame(width: 200, height: 200)
            Text(goods.name).padding()
            Text("￥\(goods.price/100)").padding()
            Text(goods.description).padding()
            Spacer()
            HStack{
                NavigationLink(destination: ConfirmOrderView(goods:goods)) {
                    Text("下单").font(.headline).frame(minWidth: 150)
                }
                .padding(EdgeInsets.init(top: 5, leading: 0, bottom: 5, trailing: 0))
                .foregroundColor(.white)
                .background(Color.main_color)
                .clipShape(RoundedRectangle(cornerRadius: 5))
            }.padding()
        }.toast(isPresenting: $showToast){
            AlertToast(type: .regular, title: "已加入购物车")
        }
    }
}


struct GoodsView_Previews: PreviewProvider {
    static var previews: some View {
        GoodsView(goods: Goods())
    }
}
